package morningClass;

import org.junit.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;

public class reflectPrc01 {

    @Test
    public void getClazz() throws Exception {
        Class<?> s1 = Class.forName("morningClass.Student");
        Class<Student> s2 = Student.class;
        Class<? extends Student> s3 = new Student().getClass();
        System.out.println(s1);
        System.out.println(s1.getName());
        System.out.println(s1.getSimpleName());
        System.out.println(s1.getPackage().getName());
    }
    @Test
    public void getCons(){
        Class<Student> s2 = Student.class;
        Constructor<?>[] constructors = s2.getConstructors();
        for (Constructor c:constructors){
            System.out.println(c.getName());
            System.out.println(Arrays.toString(c.getParameterTypes()));
        }

    }
    @Test
    public void getMethods() throws ClassNotFoundException {
        Class<Student> s2 = Student.class;
        Method[] methods = s2.getMethods();
        for (Method m:methods){
            System.out.println(m.getName());
            System.out.println(Arrays.toString(m.getParameterTypes()));
        }

    }
    @Test
    public void getFields(){
        Class<Student> s2 = Student.class;
        Field[] fields = s2.getFields();
        for (Field f:fields){
            System.out.println(f.getName());
            System.out.println(f.getType().getName());
        }

    }
}
